package com.sinosoft.sonar.controller;

import com.sinosoft.common.core.utils.StringUtils;
import com.sinosoft.sonar.domain.MyCustomer;
import com.sinosoft.sonar.examples.wrong.Demo01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.SimpleTimeZone;

/**
 * 参数配置 信息操作处理
 * 
 * @author tangyongbo
 */
@RestController
@RequestMapping("/test")
public class TestController {

    /**
     * 获取参数配置列表
     */
    @GetMapping("/demo1")
    public int demo1() {
        Demo01 demo = new Demo01();
        demo.compareByOperator();
        demo.question_20();
        String sendTime1 = "2021-12-06 16:25:25";
        String sendTime2 = "2021-12-06 16:30:25";
        MyCustomer myCustomer=new MyCustomer();
        myCustomer.setBirthDay("2000-12-06 21:25:56");

        long startTime1 = System.nanoTime();
        System.out.println("系统时间"+startTime1);
//        Date afterTime = getOneDayAfterTime(myCustomer.getBirthDay());
//        if((null != afterTime)&&(afterTime.compareTo(new Date())>0)){
//            long startTime2 = System.nanoTime();
//            System.out.println("执行耗时："+(startTime2-startTime1)+"纳秒");
//            System.out.println("客户生日:"+myCustomer.getBirthDay());
//            System.out.println("测试方法调用的次数完毕1");
//        }else{
//            long startTime3 = System.nanoTime();
//            System.out.println("执行耗时："+(startTime3-startTime1)+"纳秒");
//            System.out.println("客户生日:"+myCustomer.getBirthDay());
//            System.out.println("测试方法调用的次数完毕2");
//        }
        if((null != getOneDayAfterTime(myCustomer.getBirthDay()))&&(getOneDayAfterTime(myCustomer.getBirthDay()).compareTo(new Date())>0)){
            long startTime2 = System.nanoTime();
            System.out.println("执行耗时："+(startTime2-startTime1)+"纳秒");
            System.out.println("客户生日:"+myCustomer.getBirthDay());
            System.out.println("测试方法调用的次数完毕1");
        }else{
            long startTime3 = System.nanoTime();
            System.out.println("执行耗时："+(startTime3-startTime1)+"纳秒");
            System.out.println("客户生日:"+myCustomer.getBirthDay());
            System.out.println("测试方法调用的次数完毕2");
        }
        return demo.floatEquals();
    }

    public Date getOneDayAfterTime(String sendTime){
        if((sendTime == null)||(sendTime=="")) return null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前调用的sdf："+sdf.hashCode());
        Date d =null;
        try{
            d = sdf.parse(sendTime);
        }catch (ParseException e){
            e.printStackTrace();
        }
        if(null == d) return null;

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        calendar.add(Calendar.DATE,1);
        return calendar.getTime();
    }

}
